//
//  FBFirstViewController.m
//  VmiSJ
//
//  Created by 汪的一声就哭了！ on 2017/1/3.
//  Copyright © 2017年 汪的一声就哭了！. All rights reserved.
//
//
#import "FBFirstViewController.h"

@interface FBFirstViewController ()<RWLXViewControllerDelegate, RWSJViewControllerDelegate, SHZQViewControllerDelegate, RWMSViewControllerDelegate, UITextFieldDelegate>
@property (strong, nonatomic) IBOutlet UIButton *phoneLimitfirstBtn;
@property (strong, nonatomic) IBOutlet UIButton *phoneLimitSecBtn;
@property (strong, nonatomic) IBOutlet UIButton *phoneLimitThirdBtn;
@property (strong, nonatomic) IBOutlet UITextField *rwmcTF;
@property (strong, nonatomic) IBOutlet UITextField *rwdjTF;
@property (strong, nonatomic) IBOutlet UITextField *rwcsTF;
@property (strong, nonatomic) IBOutlet UIButton *timeLimitFirst;
@property (strong, nonatomic) IBOutlet UIButton *timeLimitSec;
@property (strong, nonatomic) IBOutlet UIButton *timeLimitThird;


@property (strong, nonatomic) IBOutlet UILabel *tsyqLabel;
@property (strong, nonatomic) IBOutlet UILabel *rwlxLabel;

@property (weak, nonatomic) IBOutlet UIView *rwlxView;
@property (strong, nonatomic) IBOutlet UIView *rwmsView;
@property (strong, nonatomic) IBOutlet UILabel *wcsjLabel;
@property (weak, nonatomic) IBOutlet UIView *rwsjView;
@property (strong, nonatomic) IBOutlet UILabel *shzqLabel;
@property (weak, nonatomic) IBOutlet UIView *shzqView;
@property (weak, nonatomic) IBOutlet UIView *jssjView;
@property (strong, nonatomic) IBOutlet UILabel *fbcsLabel;
@property (weak, nonatomic) IBOutlet UIView *fbcsView;

@end

@implementation FBFirstViewController
{
    ProvinceModel *_city;
    ProvinceModel *_province;
    NSString *_phoneLimit;
    NSString *_timeLimit;
}
//你总是愿意让我不快乐不是吗
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.title = @"发布任务";
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    tap.cancelsTouchesInView = NO;
    [self.view addGestureRecognizer:tap];
    
    UITapGestureRecognizer *rwlxTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(rwlxTapAction:)];
    [self.rwlxView addGestureRecognizer:rwlxTap];
    
    UITapGestureRecognizer *rwmsTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(rwmsTapAction:)];
    [self.rwmsView addGestureRecognizer:rwmsTap];
    
    UITapGestureRecognizer *rwsjTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(rwsjTapAction:)];
    [self.rwsjView addGestureRecognizer:rwsjTap];
    
    UITapGestureRecognizer *shzqTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(shzpTapAction:)];
    [self.shzqView addGestureRecognizer:shzqTap];
    
    UITapGestureRecognizer *jssjTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(jssjTapAction:)];
    [self.jssjView addGestureRecognizer:jssjTap];
    
    UITapGestureRecognizer *fbcsTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(fbcsTapAction:)];
    [self.fbcsView addGestureRecognizer:fbcsTap];
    

    //发布城市传值 通知中心
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(fbcsNotification:) name:@"FBCS" object:nil];
    
    _phoneLimit = @"不限";
    _timeLimit = @"不限";
}
#pragma mark ---------- 回收键盘
- (void)tapAction:(UITapGestureRecognizer *)tap
{
    [self.view endEditing:YES];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [self.view endEditing:YES];
    return YES;
}//那就滚 吧
- (void)rwlxTapAction:(UITapGestureRecognizer *)tap
{
    RWLXViewController *rwlxvC = [[RWLXViewController alloc] init];
    rwlxvC.delegate = self;
    rwlxvC.typeStr = _rwlxLabel.text;
//    viewC.titleName = @"任务描述";
//    viewC.placeHolder = @"请输入任务描述，200字以内";
    [self.navigationController pushViewController:rwlxvC animated:YES];
}
//这算什么
- (void)rwmsTapAction:(UITapGestureRecognizer *)tap
{
    RWMSViewController *viewC = [[RWMSViewController alloc] init];
    viewC.titleName = @"任务描述";
    viewC.placeHolder = @"请输入任务描述，200字以内";
    viewC.delegate = self;
    [self.navigationController pushViewController:viewC animated:YES];
}
//既然你不愿意让我快乐
- (void)rwsjTapAction:(UITapGestureRecognizer *)tap
{
    RWSJViewController *rwsjVC = [[RWSJViewController alloc] init];
    rwsjVC.delegate = self;
    rwsjVC.timeStr = self.wcsjLabel.text;
    [self.navigationController pushViewController:rwsjVC animated:YES];
}
//我没必要
- (void)shzpTapAction:(UITapGestureRecognizer *)tap
{
    SHZQViewController *shzqVC = [[SHZQViewController alloc] init];
    shzqVC.delegate = self;
    shzqVC.timeStr = self.shzqLabel.text;
    [self.navigationController pushViewController:shzqVC animated:YES];
}
//委屈自己
- (void)jssjTapAction:(UITapGestureRecognizer *)tap
{
    JSSJViewController *jssjVC = [[JSSJViewController alloc] init];
    //    viewC.titleName = @"任务描述";
    //    viewC.placeHolder = @"请输入任务描述，200字以内";
    [self.navigationController pushViewController:jssjVC animated:YES];
}
//你已经快要 超出我的底线了
- (void)fbcsTapAction:(UITapGestureRecognizer *)tap
{
    FBCSViewController *fbcsVC = [[FBCSViewController alloc] init];
    fbcsVC.provinceStr = _province;
    fbcsVC.cityStr = _city;
    [self.navigationController pushViewController:fbcsVC animated:YES];
}
#pragma mark ------------设备限制
- (IBAction)phoneLimitFirstAction:(id)sender {
    _phoneLimit = @"不限";
    [self.phoneLimitfirstBtn setImage:[UIImage imageNamed:@"选中"] forState:UIControlStateNormal];
    [self.phoneLimitSecBtn setImage:[UIImage imageNamed:@"未选中"] forState:UIControlStateNormal];
    [self.phoneLimitThirdBtn setImage:[UIImage imageNamed:@"未选中"] forState:UIControlStateNormal];
}
- (IBAction)phoneLimitSecAction:(id)sender {
    _phoneLimit = @"iOS";
    [self.phoneLimitfirstBtn setImage:[UIImage imageNamed:@"未选中"] forState:UIControlStateNormal];
    [self.phoneLimitSecBtn setImage:[UIImage imageNamed:@"选中"] forState:UIControlStateNormal];
    [self.phoneLimitThirdBtn setImage:[UIImage imageNamed:@"未选中"] forState:UIControlStateNormal];
}
- (IBAction)phoneLimitThirdAction:(id)sender {
    _phoneLimit = @"Android";
    [self.phoneLimitfirstBtn setImage:[UIImage imageNamed:@"未选中"] forState:UIControlStateNormal];
    [self.phoneLimitSecBtn setImage:[UIImage imageNamed:@"未选中"] forState:UIControlStateNormal];
    [self.phoneLimitThirdBtn setImage:[UIImage imageNamed:@"选中"] forState:UIControlStateNormal];
}
#pragma mark --------- 次数限制
- (IBAction)timeLimitFirstAction:(id)sender {
    _timeLimit = @"不限";
    [self.timeLimitFirst setImage:[UIImage imageNamed:@"选中"] forState:UIControlStateNormal];
    [self.timeLimitSec setImage:[UIImage imageNamed:@"未选中"] forState:UIControlStateNormal];
    [self.timeLimitThird setImage:[UIImage imageNamed:@"未选中"] forState:UIControlStateNormal];
}
- (IBAction)timeLimitSecAction:(id)sender {
    _timeLimit = @"每人限一次";
    [self.timeLimitFirst setImage:[UIImage imageNamed:@"未选中"] forState:UIControlStateNormal];
    [self.timeLimitSec setImage:[UIImage imageNamed:@"选中"] forState:UIControlStateNormal];
    [self.timeLimitThird setImage:[UIImage imageNamed:@"未选中"] forState:UIControlStateNormal];
}
- (IBAction)timeLimitThirdAction:(id)sender {
    _timeLimit = @"每人每天限一次";
    [self.timeLimitFirst setImage:[UIImage imageNamed:@"未选中"] forState:UIControlStateNormal];
    [self.timeLimitSec setImage:[UIImage imageNamed:@"未选中"] forState:UIControlStateNormal];
    [self.timeLimitThird setImage:[UIImage imageNamed:@"选中"] forState:UIControlStateNormal];
}
#pragma mark ---------- 下一步
- (IBAction)nextTypeAction:(id)sender {
    if ([_rwlxLabel.text isEqualToString:@"请选择任务类型"] || [self.rwmcTF.text isEqualToString:@""] || [self.tsyqLabel.text isEqualToString:@"特殊要求，200字以内"] || [self.rwdjTF.text isEqualToString:@""] || [self.rwcsTF.text isEqualToString:@""] || [self.wcsjLabel.text isEqualToString:@"请选择完成时间"] || [self.shzqLabel.text isEqualToString:@"请选择审核周期"] || !_province || !_city) {
        [[SQShowMessage shareMessage] showMessageWithStr:@"请填写完整信息"];
    } else {
        FBSecViewController *viewC = [[FBSecViewController alloc] init];
        [self.navigationController pushViewController:viewC animated:YES];
    }
}

#pragma mark ---------- 代理传值
//任务类型
- (void)RWLXViewControllerSendType:(RWLXModel *)type
{
    _rwlxLabel.text = type.c_name;
}
//完成时间
- (void)RWSJViewControllerSendType:(NSString *)timeStr
{
    _wcsjLabel.text = timeStr;
}
//审核周期
- (void)SHZQViewControllerSendType:(NSString *)timeStr
{
    _shzqLabel.text = timeStr;
}
//任务描述
- (void)RWMSViewControllerSendRWMSWithStr:(NSString *)string
{
    self.tsyqLabel.text = string;
    NSLog(@"%@",self.tsyqLabel.text);
}
//发布城市
- (void)fbcsNotification:(NSNotification *)noti
{
    _province = noti.userInfo[@"province"];
    _city = noti.userInfo[@"city"];
    _fbcsLabel.text = [NSString stringWithFormat:@"%@ %@",_province.categoryname, _city.categoryname];
}
- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
@end
